#include <iostream>


const int capacity = 10;
class MinHeap
{
public:
    MinHeap():size(0){}
    void Insert(int value)
    {
        if(size == capacity)
            return;
        array[size] = value;
        SifwUp(size);
        size++;
    }

    void Remove()
    {
        if(size == 0)
            return;
        array[0] = array[--size];
        SifwDown(0);
    }

    void show()
    {
        for(int i = 0;i < size;i++)
            std::cout<<array[i]<<" ";
        std::cout<<std::endl;
    }

private:
    int array[capacity];
    int size;

    int GetParent(int i){return (i -1) / 2;}
    int GetLefChild(int i){return 2*i + 1;}
    int GetRightChild(int i){return 2*i + 2;}

    void SifwUp(int i)
    {
        while(i > 0 && array[i] < array[GetParent(i)])
        {
            std::swap(array[i],array[GetParent(i)]);
            i = GetParent(i);
        }
    }

    void SifwDown(int i)
    {
        int left = GetLefChild(i);
        int right = GetRightChild(i);
        int min = i;
        if(left < size && array[left] < array[min])
            min = left;
        if(right < size && array[right] < array[min])
            min = right;
        if(min != i)
        {
            std::swap(array[i],array[min]);
            SifwDown(min); 
        }
    }
};

int main()
{
    MinHeap h;
    for(int i = 1;i <= 10;i++)
        h.Insert(i);
    h.show();

    return 0;
}